home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / batch / Notify10.lha / Notify / Notify.s < prev   
Text File  |  1994-12-19  |  8KB  |  362 lines

  1.  
  2.         ***************************************************
  3.         ***                        ***
  4.         ***             Notify 1.0            ***
  5.         ***                        ***
  6.         ***************************************************
  7.         ***   © 19.12.94 by Marc Heuler (Data Design)    ***
  8.         ***************************************************
  9.  
  10.         INCDIR    "Include:"
  11.         INCLUDE    "exec/types.i"
  12.         INCLUDE    "exec/libraries.i"
  13.         INCLUDE    "exec/ports.i"
  14.         INCLUDE    "exec/execbase.i"
  15.         INCLUDE    "utility/tagitem.i"
  16.         INCLUDE    "dos/dosextens.i"
  17.         INCLUDE    "dos/notify.i"
  18.         INCLUDE    "devices/timer.i"
  19.         INCLUDE    "LVO.i"
  20.  
  21. CALLEXE        MACRO
  22.         move.l    _SysBase(pc),a6
  23.         jsr    _LVO\1(a6)
  24.         ENDM
  25.  
  26. CALLDOS        MACRO
  27.         move.l    _DosBase(pc),a6
  28.         jsr    _LVO\1(a6)
  29.         ENDM
  30.  
  31. NAME        MACRO
  32.         dc.b    "Notify"
  33.         ENDM
  34.  
  35. VERSION        MACRO
  36.         dc.b    "1.00"
  37.         ENDM
  38.  
  39. DATE        MACRO
  40.         dc.b    "19.12.94"
  41.         ENDM
  42.  
  43.  
  44. Start        bra.s    RStart
  45.  
  46.         dc.b    "$VER: "
  47.         NAME
  48.         dc.b    " "
  49.         VERSION
  50.         dc.b    " ("
  51.         DATE
  52.         dc.b    ") © 1994 by Marc 'Nepomuk' Heuler <marc@aargh.incubus.sub.org>",0
  53.         even
  54.  
  55.         ***************************************************
  56.         ***                        ***
  57.         ***            Start            ***
  58.         ***                        ***
  59.         ***************************************************
  60.  
  61. RStart        movem.l    d1-d7/a0-a6,-(a7)
  62.         move.l    4,_SysBase
  63.         moveq    #-1,d4
  64.         moveq    #0,d5
  65.         moveq    #0,d6
  66.         moveq    #0,d7
  67.  
  68.         lea    _DosName(pc),a1            ; Open DOS
  69.         moveq    #33,d0
  70.         CALLEXE    OpenLibrary
  71.         move.l    d0,_DosBase
  72.         beq    .Error
  73.  
  74.         move.l    d0,a0                ; DOS 37+ required
  75.         cmp.w    #37,LIB_VERSION(a0)
  76.         blt    .Error_Kick
  77.  
  78.         move.l    #_Template,d1            ; Get arguments
  79.         move.l    #_Name,d2
  80.         moveq    #0,d3
  81.         CALLDOS    ReadArgs
  82.         move.l    d0,_Args
  83.         beq    .Error_DOS
  84.  
  85.         ***************************************************
  86.         ***        Open timer.device        ***
  87.         ***************************************************
  88.  
  89.         tst.l    _Delay                ; Do we need the timer?
  90.         beq    .StartNotify
  91.  
  92.         CALLEXE    CreateMsgPort            ; Get message port
  93.         move.l    d0,d6
  94.         beq    .Error
  95.  
  96.         lea    TimerIOB(pc),a1            ; Open device
  97.         move.l    d6,MN_REPLYPORT(a1)
  98.         lea    _TimerName(pc),a0
  99.         moveq    #UNIT_VBLANK,d0
  100.         moveq    #0,d1
  101.         CALLEXE    OpenDevice
  102.         tst.l    d0
  103.         bne    .Error
  104.         st    d7
  105.  
  106. .StartNotify    ***************************************************
  107.         ***         Expand filename        ***
  108.         ***************************************************
  109.  
  110.         move.l    _SysBase(pc),a0            ; Suppress requesters
  111.         move.l    ThisTask(a0),a0
  112.         move.l    pr_WindowPtr(a0),d0
  113.         movem.l    d0/a0,-(sp)
  114.         move.l    #-1,pr_WindowPtr(a0)
  115.  
  116.         move.l    _Name(pc),d1            ; Lock file
  117.         move.l    #ACCESS_READ,d2
  118.         CALLDOS    Lock
  119.         move.l    d0,d4
  120.  
  121.         movem.l    (sp)+,d0/a0            ; Re-allow requesters
  122.         move.l    d0,pr_WindowPtr(a0)
  123.  
  124.         tst.l    d4                ; Lock succeeded?
  125.         beq.s    .CopyName
  126.  
  127.         move.l    d4,d1                ; Get name
  128.         move.l    #Buffer,d2
  129.         move.l    #BufferEnd-Buffer,d3
  130.         CALLDOS    NameFromLock
  131.         move.l    d0,-(sp)
  132.  
  133.         move.l    d4,d1                ; Unlock file
  134.         CALLDOS    UnLock
  135.  
  136.         moveq    #0,d4                ; Check success
  137.         tst.l    (sp)+
  138.         beq    .Error_DOS
  139.         bra.s    .DoNotification
  140.  
  141. .CopyName    move.l    _Name(pc),a0            ; Copy supplied name
  142.         lea    Buffer,a1
  143.         move.l    #BufferEnd-Buffer,d0
  144. .CopyLoop    subq.l    #1,d0
  145.         bmi.s    .CopyError
  146.         move.b    (a0)+,(a1)+
  147.         bne.s    .CopyLoop
  148.         bra.s    .DoNotification
  149. .CopyError    move.l    #ERROR_LINE_TOO_LONG,d1
  150.         CALLDOS    SetIoErr
  151.         bra    .Error_DOS
  152.  
  153. .DoNotification    ***************************************************
  154.         ***        Start notification        ***
  155.         ***************************************************
  156.  
  157.         moveq    #-1,d0                ; Allocate signal bit
  158.         CALLEXE    AllocSignal
  159.         move.l    d0,d4
  160.         tst.b    d4
  161.         beq    .Error
  162.  
  163.         lea    NotifyReq(pc),a1        ; Fill in notify request
  164.         move.l    _Name(pc),nr_Name(a1)
  165.         beq    .Error
  166.         move.l    ThisTask(a6),nr_Task(a1)
  167.         move.b    d4,nr_SignalNum(a1)
  168.         move.l    #NRF_SEND_SIGNAL,nr_Flags(a1)
  169.  
  170.         move.l    a1,d1                ; Activate
  171.         CALLDOS    StartNotify
  172.         tst.l    d0
  173.         beq    .Error_DOS
  174.         st    d5
  175.  
  176.         ***************************************************
  177.         ***        Wait for activity        ***
  178.         ***************************************************
  179.  
  180. .Loop        move.l    #SIGBREAKF_CTRL_C,d0        ; Wait
  181.         bset    d4,d0
  182.         CALLEXE    Wait
  183.         moveq    #SIGBREAKB_CTRL_C,d1
  184.         btst    d1,d0
  185.         bne    .Break
  186.  
  187. .TimerLoop    move.l    _Delay(pc),d0            ; Delay specified?
  188.         beq    .Command
  189.         move.l    d0,a0
  190.  
  191.         lea    TimerIOB(pc),a1            ; Start timer
  192.         move.w    #TR_ADDREQUEST,IO_COMMAND(a1)
  193.         move.l    (a0),IOTV_TIME+TV_SECS(a1)
  194.         clr.l    IOTV_TIME+TV_MICRO(a1)
  195.         CALLEXE    SendIO
  196.  
  197.         move.l    #SIGBREAKF_CTRL_C,d0        ; Wait again
  198.         bset    d4,d0
  199.         move.l    TimerIOB+MN_REPLYPORT(pc),a0
  200.         move.b    MP_SIGBIT(a0),d1
  201.         bset    d1,d0
  202.         CALLEXE    Wait
  203.  
  204.         move.l    d0,-(sp)
  205.         lea    TimerIOB(pc),a1            ; Abort timer
  206.         CALLEXE    AbortIO
  207.         lea    TimerIOB(pc),a1
  208.         CALLEXE    WaitIO
  209.         move.l    TimerIOB+MN_REPLYPORT(pc),a0    ; Clear timer signal
  210.         move.b    MP_SIGBIT(a0),d0
  211.         bset    d0,d1
  212.         moveq    #0,d0
  213.         CALLEXE    SetSignal
  214.         move.l    (sp)+,d0
  215.  
  216.         moveq    #SIGBREAKB_CTRL_C,d1        ; Examine signals
  217.         btst    d1,d0
  218.         bne    .Break
  219.         btst    d4,d0                ; Another notification?
  220.         bne.s    .TimerLoop
  221.  
  222.         ***************************************************
  223.         ***           Start command        ***
  224.         ***************************************************
  225.  
  226. .Command    move.l    _Command(pc),d1            ; Script mode?
  227.         beq.s    .NoCMD
  228.  
  229.         move.l    #.Tags,d2            ; Execute command
  230.         CALLDOS    SystemTagList
  231.  
  232.         tst.l    _Stay                ; Stay in memory?
  233.         bne    .Loop
  234.  
  235. .NoCMD        moveq    #0,d0
  236.         bra.s    .Cleanup
  237.  
  238. .Tags        dc.l    TAG_DONE,0
  239.  
  240.         ***************************************************
  241.         ***          Error handling        ***
  242.         ***************************************************
  243.  
  244. .Break        lea    .tx_Break(pc),a0
  245.         bsr    Print
  246.         moveq    #10,d0
  247.         bra.s    .Cleanup
  248.  
  249. .Error_Kick    lea    .tx_Kick(pc),a0            ; Wrong Kickstart
  250.         bsr    Print
  251.         bra.s    .Error
  252.  
  253. .Error_DOS    CALLDOS    IoErr                ; DOS error
  254.         move.l    d0,d1
  255.         move.l    #.tx_Name,d2
  256.         CALLDOS    PrintFault
  257.  
  258. .Error        moveq    #20,d0
  259.         bra.s    .Cleanup
  260.  
  261. .tx_Break    dc.b    "***Break",$a,0
  262. .tx_Name    NAME
  263.         dc.b    0
  264. .tx_Kick    dc.b    "You need at least Kickstart 2.04 (v37)"
  265. .tx_CR        dc.b    $a,0
  266.         even
  267.  
  268.         ***************************************************
  269.         ***              Cleanup            ***
  270.         ***************************************************
  271.  
  272. .Cleanup    move.l    d0,-(a7)
  273.  
  274.         tst.b    d7                ; Close timer.device
  275.         beq.s    .NoTimer
  276.         lea    TimerIOB(pc),a1
  277.         CALLEXE    CloseDevice
  278. .NoTimer    tst.l    d6                ; Remove msg port
  279.         beq.s    .NoPort
  280.         move.l    d6,a0
  281.         CALLEXE    DeleteMsgPort
  282. .NoPort        tst.b    d5                ; Stop notification
  283.         beq.s    .NoNotify
  284.         move.l    #NotifyReq,d1
  285.         CALLDOS    EndNotify
  286. .NoNotify    tst.b    d4                ; Free signal bit
  287.         bmi.s    .NoSignal
  288.         move.l    d4,d0
  289.         CALLEXE    FreeSignal
  290. .NoSignal    move.l    _Args(pc),d1            ; Free Args
  291.         beq.s    .NoArgs
  292.         CALLDOS    FreeArgs
  293. .NoArgs        move.l    _DosBase(pc),d0            ; Close DOS
  294.         beq.s    .NoDos
  295.         move.l    d0,a1
  296.         CALLEXE    CloseLibrary
  297. .NoDos        move.l    (a7)+,d0
  298.         movem.l    (a7)+,d1-d7/a0-a6
  299.         rts
  300.  
  301.         ***************************************************
  302.         ***                        ***
  303.         ***        Print To StdOutput        ***
  304.         ***                        ***
  305.         ***************************************************
  306.         *** >>> A0    String (0-terminated)        ***
  307.         *** <<< FLAGS    BNE ERROR            ***
  308.         ***************************************************
  309.  
  310. Print        movem.l    d1-d3/a0-a1,-(a7)
  311.         move.l    _DosBase(pc),d0
  312.         beq.s    .Print_Skip
  313.         move.l    a0,-(a7)
  314.         CALLDOS    Output
  315.         move.l    d0,d1
  316.         move.l    (a7)+,a0
  317.         move.l    a0,d2
  318. .Print_Loop    tst.b    (a0)+
  319.         bne.s    .Print_Loop
  320.         move.l    a0,d3
  321.         subq.l    #1,d3
  322.         sub.l    d2,d3
  323.         beq.s    .Print_Skip
  324.         move.l    d3,-(a7)
  325.         CALLDOS    Write
  326.         sub.l    (a7)+,d0
  327. .Print_Skip    movem.l    (a7)+,d1-d3/a0-a1
  328.         rts
  329.  
  330.         ***************************************************
  331.         ***                        ***
  332.         ***             Variables            ***
  333.         ***                        ***
  334.         ***************************************************
  335.  
  336. _Args        dc.l    0
  337. _SysBase    dc.l    0
  338. _DosBase    dc.l    0
  339.  
  340. _Name        dc.l    0
  341. _Command    dc.l    0
  342. _Delay        dc.l    0
  343. _Stay        dc.l    0
  344.  
  345. NotifyReq    dcb.b    NotifyRequest_SIZEOF,0
  346.  
  347. TimerIOB    dcb.b    IOTV_SIZE,0
  348.  
  349.  
  350. _TimerName    dc.b    "timer.device",0
  351. _DosName    dc.b    "dos.library",0
  352. _Template    dc.b    "NAME/A,COMMAND,DELAY/N,STAY/S",0
  353.         even
  354.  
  355.         SECTION    Buf,bss
  356.  
  357. Buffer        ds.b    1024
  358. BufferEnd
  359.  
  360.         END
  361.  
  362.